package com.qf.aop;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.AfterReturningAdvice;
import org.springframework.aop.MethodBeforeAdvice;

import java.lang.reflect.Method;

/*
 *@Description:
 *@author:刘哥
 *@Date:86180 2022/8/26 19:14
 */
//@Repository
public class Around implements MethodInterceptor {

    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        Object proceed = null;
        try {
            System.out.println("填写数据");
            //放行并获取到原始的执行结果
            proceed = invocation.proceed();
            System.out.println("添加用户成功");
        } catch (Throwable e) {
            System.out.println("添加用户失败");
        } finally {
            System.out.println("需要再次添加吗");
        }
//自己可以定义返回什么值，但返回值类型需要符合被代理的对象的方法返回值类型
        return proceed;
    }
}
